public class LCSubstring {
    public static int lcs(String a, String b){
        int[][] dp = new int[b.length()][a.length()];
        int max = 0;
        for (int i = 0; i < b.length(); i++){
            for (int j = 0; j < a.length(); j++){
                if (b.charAt(j) == a.charAt(j)){
                    if (i == 0 || j == 0){
                        dp[i][j] = 1;
                    }else {
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                    }
                    max = Integer.max(max, dp[i][j]);
                }else {
                    dp[i][j] = 0;
                }
            }
        }
        return max;
    }
}
